package cn.buk.tms.eotms.response;

import cn.buk.common.flight.dto.FlightBasicInfo;
import cn.buk.common.util.DateUtil;
import cn.buk.tms.common.dto.CustomerDto;
import cn.buk.tms.common.dto.flight.BaseRefundOrderDto;
import cn.buk.tms.eotms.entity.FlightRefundOrder;
import cn.buk.tms.eotms.entity.FlightRefundOrderDetail;
import org.springframework.beans.BeanUtils;

import java.text.ParseException;

public class RefundOrderResponseDto extends BaseRefundOrderDto {
  public static RefundOrderResponseDto createBy(FlightRefundOrder o) {
    RefundOrderResponseDto dto = new RefundOrderResponseDto();
    BeanUtils.copyProperties(o, dto, "flights");

    dto.setParValue(o.getParvalue());
//        dto.setPassengerRefundAmount();
    dto.setCustomer(CustomerDto.create(o.getCustomer().getId(), o.getCustomer().getVipName(), o.getCustomer().getCustomerCode()));
    dto.setOrderStatus(o.getStatus());

    for(FlightRefundOrderDetail d: o.getFlights()) {
      FlightBasicInfo flightInfoDto = new FlightBasicInfo();
      BeanUtils.copyProperties(d.getFlight(), flightInfoDto);

      try {
        flightInfoDto.setDdate(DateUtil.convertToDate(d.getFlight().getDdate()));
      } catch (ParseException e) {
//        e.printStackTrace();
      }

      dto.getFlights().add(flightInfoDto);
    }

    return dto;
  }
}
